package com.itheima.service;

import com.itheima.mapper.UserMapper;
import com.itheima.mapper.impl.UserMapperImpl;
import com.itheima.pojo.User;

/**
 * 用户业务类
 */
public class UserService {

    private UserMapper userMapper = new UserMapperImpl();

    public User login(String username, String password) {
        return userMapper.select(username, password);
    }

    /**
     * 如果注册成功返回true，否则返回false
     * @param user
     * @return
     */
    public boolean register(User user) {
        //1. 通过用户名查询用户是否存在
        User byUsername = userMapper.selectByUsername(user.getUsername());
        //2.如果存在返回false
        if (byUsername != null) {
            return false;
        }
        else {
            //不存在就添加用户
            userMapper.add(user);
            return true;
        }
    }
}
